using InfluxDBClient;

namespace ApiExtenionTestProject;

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        ICanByApi client = new ApiExtension("172.26.172.124:18102", "se",
            "bApKNPs311DTEEKhJTZ2c_oO56AhvJ6gmWSasdKTxhe4dedQgLU8rzclQ7yzMKA3jDUd00_MlF4aqZcIaSSUdg==", "po");
        var sript = @"import ""timezone""
option location = timezone.fixed (offset: 8h)
from(bucket: ""po"")
    |> range(start: 2021-06-01T00:00:00Z, stop: 2021-07-01T00:00:00Z)
    |> filter(  fn: (r) => r.tag == ""T2C1.DA_IDC11_1A_InA\\FRONT\\Temp1"" )
    |> group(columns: [""tag""])
    |>count()";
        var result = client.Query(sript);
        var item = result.First();
        Assert.Equal(@"T2C1.DA_IDC11_1A_InA\FRONT\Temp1", item.tag);
        Assert.Equal(8457, item.val);
    }
    
    [Fact]
    public async Task WriteTest1()
    {
        ICanByApi client = new ApiExtension("172.26.172.124:18102", "se",
            "bApKNPs311DTEEKhJTZ2c_oO56AhvJ6gmWSasdKTxhe4dedQgLU8rzclQ7yzMKA3jDUd00_MlF4aqZcIaSSUdg==", "po");
        Random ran = new Random();
        int n = ran.Next(100,9999);
        int i = 0;
        while (true)
        {
            Thread.Sleep(1000);
            var result =await client.Write("TrendData",new List<(string tag, double val, string ts)>()
            {
                new ("T2C1.DA_IDC11_1A_InA\\FRONT\\Temp1",ran.Next(100,9999),$"{1711900800000+i*5000}")
            });
            i++;
        }
        
      
        // Assert.Equal("", result);
    }
}